package cn.lg.soar.message.client;

import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.message.api.constant.ModuleConst;
import cn.lg.soar.message.api.model.WebSocketDTO;
import cn.lg.soar.message.api.service.ISseApi;
import cn.lg.soar.message.service.SseService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/sse")
public class SseApiClient implements ISseApi {

    private final SseService service;

    public SseApiClient(SseService service) {
        this.service = service;
    }

    @PostMapping("broadcast")
    @Override
    public Collection<Long> broadcast(@RequestParam String topic, @RequestBody String message) {
        return service.sendMsgAll(topic, message);
    }

    @PostMapping("sendMessage")
    @Override
    public  Collection<Long> sendMessage(@RequestParam String topic, @RequestBody WebSocketDTO dto) {
        return service.sendMsgByUser(topic, dto.getMessage(), dto.getUserIds());
    }

}
